package sql;

import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class JDBCUtil {
	/*
	 * 提供数据库连接
	 */
	/*
	public static Connection getcon() throws Exception {
		Reader reader = new FileReader("/db.properties");
		Properties pros = new Properties();
		pros.load(reader);
		
		Class.forName(pros.getProperty("jdbc.driver"));
		String url = pros.getProperty("jdbc.url");
		String username = pros.getProperty("jdbc.name");
		String password = pros.getProperty("jdbc.pass");
		Connection con = DriverManager.getConnection(url, username, password);
		
		reader.close();
		return con;
	}
	*/
	public static Connection getcon() throws Exception {
		// Reader reader = new FileReader("/db.properties");
		// Properties pros = new Properties();
		// pros.load(reader);
		String driver = "com.mysql.cj.jdbc.Driver";
		String url= "jdbc:mysql://localhost:3306/park";
		String name = "root";
		String pass = "Lxj13430230121";
		Class.forName(driver);
		Connection con = DriverManager.getConnection(url, name, pass);
		return con;
	}
	public static void close(ResultSet rs, Statement ps, Connection con) throws SQLException {
		if(rs != null)
			rs.close();
		if(ps != null)
			ps.close();
		if(con != null)
			con.close();
	}
}
